<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form id="form">

                    <p:panel header="Manage Investigation Report Items" >
                        <p:panelGrid columns="2" styleClass="alignTop" >
                            <p:panelGrid columns="1" id="filters" >
                                <h:panelGrid columns="2" >
                                    <p:commandButton value="Previous" id="btnPre"
                                                     action="#{investigationItemController.previousInvestigation()}"
                                                     process="@this" ajax="false"
                                                     update="acPt tbl filters"  disabled="#{investigationItemController.currentInvestigation eq null}"
                                                     ></p:commandButton>
                                    <p:commandButton value="Next" disabled="#{investigationItemController.currentInvestigation eq null}"
                                                     action="#{investigationItemController.nextInvestigation()}"
                                                     process="@this" ajax="false"
                                                     update="acPt tbl filters" id="btnNext"
                                                     ></p:commandButton>

                                </h:panelGrid>
                                <p:outputLabel value="Search Investigation" ></p:outputLabel>
                                <p:autoComplete widgetVar="aPt" id="acPt" forceSelection="true" converter="ixcon"
                                                value="#{investigationItemController.currentInvestigation}" 
                                                completeMethod="#{investigationController.completeInvestigationsOfCurrentInstitution}" 
                                                var="apt" itemLabel="#{apt.name}" 
                                                itemValue="#{apt}" size="30" maxResults="10"  style="width: 400px;">
                                    <p:column headerText="Name" >
                                        <h:outputLabel value="#{apt.name}" ></h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Code" >
                                        <h:outputLabel value="#{apt.code}" ></h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Printing Name" >
                                        <h:outputLabel value="#{apt.printName}" ></h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Fill Name" >
                                        <h:outputLabel value="#{apt.fullName}" ></h:outputLabel>
                                    </p:column>
                                    <p:ajax event="itemSelect" process="acPt" 
                                            update="tbl filters"/>
                                </p:autoComplete> 
                                <p:panelGrid columns="2" >
                                    <p:outputLabel value="Sample" ></p:outputLabel>
                                    <p:outputLabel value="#{investigationItemController.currentInvestigation.sample.name}" ></p:outputLabel>
                                    <p:outputLabel value="Container" ></p:outputLabel>
                                    <p:outputLabel value="#{investigationItemController.currentInvestigation.investigationTube.name}" ></p:outputLabel>
                                    <p:outputLabel value="Analyzer" ></p:outputLabel>
                                    <p:outputLabel value="#{investigationItemController.currentInvestigation.machine.name}" ></p:outputLabel>

                                    <p:outputLabel value="Components" ></p:outputLabel>
                                    <h:panelGroup >
                                        <ui:repeat value="#{itemController.getInvestigationSampleComponents(investigationItemController.currentInvestigation)}" var="s" >
                                            <p:outputLabel value=" |#{s.name}| " ></p:outputLabel>
                                        </ui:repeat>
                                    </h:panelGroup>

                                </p:panelGrid>
                                <p:commandButton id="btnEditDetails" value="Edit Details" process="@this tbl" update="ixitemDetails"
                                                 oncomplete="PF('ixitemDetails').show()"  
                                                 disabled="#{investigationItemController.current eq null}">
                                </p:commandButton>

                              



                                <p:commandButton id="btnMatch" value="Make All to Match Investigation" 
                                                 ajax="false" action="#{investigationItemController.makeAllIxItemsToMachIxDetails}">
                                </p:commandButton>
                                
                                
                                  <p:commandButton id="btnIxMaster" value="Back to Investigations" 
                                                 ajax="false" action="/lab/investigation"
                                                 actionListener="#{investigationItemController.toInvestigationMaster()}"
                                                 disabled="#{investigationItemController.current eq null}">
                                </p:commandButton>

                                <p:dialog id="ixitemDetails" widgetVar="ixitemDetails" >
                                    <p:commandButton value="Save" action="#{investigationItemController.saveSelected()}" 
                                                     process="@this pDetails" update="tbl"
                                                     oncomplete="PF('ixitemDetails').hide()">
                                    </p:commandButton>
                                    <p:panel  id="pDetails" >
                                        <p:panelGrid style="width: 95%;" >
                                            <p:row >
                                                <p:column >
                                                    <h:outputText value="Name"   />
                                                </p:column>
                                                <p:column colspan="4" >
                                                    <p:inputText style="min-width: 400px!important;" autocomplete="off" id="lblIiName" value="#{investigationItemController.current.name}" >
                                                    </p:inputText>
                                                </p:column>
                                            </p:row>
                                            <p:row >
                                                <p:column >
                                                    <h:outputText value="Type"/>
                                                </p:column>
                                                <p:column >
                                                    <p:selectOneMenu id="cmbItemType" 
                                                                     value="#{investigationItemController.current.ixItemType}" >
                                                        <f:selectItem itemLabel="Please select" />
                                                        <f:selectItem itemLabel="Label" itemValue="Label"/>
                                                        <f:selectItem itemLabel="Value" itemValue="Value"/>
                                                        <f:selectItem itemLabel="Calculation" itemValue="Calculation"/>
                                                        <f:selectItem itemLabel="Flag" itemValue="Flag"/>
                                                        <f:selectItem itemLabel="List" itemValue="List"/>
                                                        <f:selectItem itemLabel="Dynamic Label" itemValue="DynamicLabel"/>
                                                        <f:selectItem itemLabel="Investigation" itemValue="Investigation"/>
                                                        <f:selectItem itemLabel="Template" itemValue="Template"/>
                                                    </p:selectOneMenu>
                                                </p:column>
                                                <p:column >
                                                    <p:spacer height="1" width="5"></p:spacer>
                                                </p:column>
                                                <p:column >
                                                    <h:outputText value="Value Type"/>
                                                </p:column>
                                                <p:column >
                                                    <p:selectOneMenu id="cmbValueType" value="#{investigationItemController.current.ixItemValueType}"  >
                                                        <f:selectItem itemLabel="Please select" />
                                                        <f:selectItems value="#{enumController.investigationItemValueTypes}" ></f:selectItems>
                                                    </p:selectOneMenu>
                                                </p:column>
                                            </p:row>

                                        </p:panelGrid>
                                        <p:panelGrid columns="2" >
                                            <h:outputText value="Automated"/>
                                            <p:selectBooleanCheckbox value="#{investigationItemController.current.automated}" itemLabel="Automated" ></p:selectBooleanCheckbox>



                                            <p:outputLabel value="Test Component" ></p:outputLabel>
                                            <p:selectOneMenu id="cmbTestComponent"  value="#{investigationItemController.current.sampleComponent}" >
                                                <f:selectItems value="#{investigationItemController.currentReportComponants}" var="cat" itemLabel="#{cat.name}" itemValue="#{cat}" />
                                            </p:selectOneMenu>

                                            <h:outputText value="Machine"/>
                                            <p:selectOneMenu value="#{investigationItemController.current.machine}" >
                                                <f:selectItem itemLabel="Select" ></f:selectItem>
                                                <f:selectItems value="#{machineController.institutionMachines}" ></f:selectItems>
                                            </p:selectOneMenu>

                                            <h:outputText value="Test"/>
                                            <p:autoComplete value="#{investigationItemController.current.test}"
                                                            completeMethod="#{itemController.completeMachineTests}"
                                                            var="t" inputStyle="width:200px;"
                                                            itemValue="#{t}"
                                                            itemLabel="#{t.code}"
                                                            >
                                                <p:column >
                                                    <p:outputLabel value="#{t.code}" ></p:outputLabel>
                                                </p:column>
                                                <p:column >
                                                    <p:outputLabel value="#{t.name}" ></p:outputLabel>
                                                </p:column>
                                            </p:autoComplete>

                                            <p:outputLabel value="Sample" ></p:outputLabel>
                                            <p:selectOneMenu id="cmbSample"  value="#{investigationItemController.current.sample}" >
                                                <f:selectItem itemLabel="Please select a sample"/>
                                                <f:selectItems value="#{sampleController.items}" var="cat" itemLabel="#{cat.name}" itemValue="#{cat}" />
                                            </p:selectOneMenu>

                                            <h:outputText value="Container / Tube" ></h:outputText>
                                            <p:selectOneMenu id="cmbTube"  value="#{investigationItemController.current.tube}" >
                                                <f:selectItem itemLabel="Please select a Tube"/>
                                                <f:selectItems value="#{investigationTubeController.items}" var="cat" itemLabel="#{cat.name}" itemValue="#{cat}" />
                                            </p:selectOneMenu>
                                        </p:panelGrid>
                                    </p:panel>
                                </p:dialog>
                            </p:panelGrid>
                            <p:panelGrid columns="1" >
                                <p:dataTable id="tbl" value="#{investigationItemController.importantItems}" var="ii"
                                             selectionMode="single" rowKey="#{ii.id}" selection="#{investigationItemController.current}">

                                    <p:ajax event="rowSelect" process="@this" update=":#{p:component('ixitemDetails')} :#{p:component('filters')}" />
                                    <p:ajax event="rowUnselect" process="@this" update=":#{p:component('ixitemDetails')}  :#{p:component('filters')}" />

                                    <p:column headerText="ID"  >
                                        <p:outputLabel value="#{ii.item.id}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Name"  >
                                        <p:outputLabel value="#{ii.name}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Type" sortBy="#{ii.ixItemType}" filterBy="#{ii.ixItemType}">
                                        <p:outputLabel value="#{ii.ixItemType}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Automated" >
                                        <p:outputLabel value="#{ii.automated?'Automated':'Not automated'}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Test Componant" >
                                        <p:outputLabel value="#{ii.sampleComponent.name}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Machine" >
                                        <p:outputLabel value="#{ii.machine.name}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Test" >
                                        <p:outputLabel value="#{ii.test.name}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Result Code" >
                                        <p:outputLabel value="#{ii.resultCode}" ></p:outputLabel>
                                    </p:column>
                                    
                                    <p:column headerText="Sample" >
                                        <p:outputLabel value="#{ii.sample.name}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Tube" >
                                        <p:outputLabel value="#{ii.tube.name}" ></p:outputLabel>
                                    </p:column>
                                </p:dataTable>
                            </p:panelGrid>


                        </p:panelGrid>


                    </p:panel>

















                </h:form>

            </ui:define>

        </ui:composition>

    </body>
</html>
